<%@page import="org.madmac.ip.IpBo"%>
<%@page import="org.madmac.join.PlacaRedeXMaquinas"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
			pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- VERIFICA SE O USUÁRIO ESTÁ COM O COOKIE VÁLIDO, SENÃO O REDIRECIONA PARA A PÁGINA DE LOGIN -->
<%@ include file="/log/verify_login.jsp" %>

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Buscar IP</title>
      <link rel="icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="shortcut icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/madmac/menu_madmac_files/cbcscbmenu_madmac.css" type="text/css" />
		<link rel="stylesheet" href="/madmac/estilos/madmac_tables.css" type="text/css" />
      <link rel="stylesheet" href="/madmac/estilos/madmac_inputs.css" type="text/css" />
		<link rel="stylesheet" href="/madmac/estilos/madmac_others.css" type="text/css" />
      <script type="text/javascript" src="/madmac/madmacproject.js"></script>
   </head>
   <body onload="document.getElementById('search_ip').focus()">
      <div class="logotype"><img src="/madmac/madmac-logo-1.0.1.png" height="120%" alt="MAD MAC"></div>

      <div class="menu_principal">
			<%@ include file="/common_pages/menu.jsp" %>
      </div>

      <div class="search_mac">
			<%@include file="/common_pages/search_mac.jsp" %>
      </div>

      <div class="corpo">

			<p></p>
			<form name="search_ip" action="/madmac/ip/buscar_ip.jsp" method="get" onsubmit="validate_search_ip()">
				<center>
					<fieldset class="box_search" style="width: 40%">
						<legend><b>Buscar Ip</b></legend>
						<table width="100%" align="center" border="0" cellpadding="5" cellspacing="0" rules="all" class="main_table">
							<tr>
								<td width="14%"></td>
								<td class="data_cell" align="right">
									<input type="text" name="search_ip" id="search_ip" size="50" maxlength="18" class="input_fields"
											 title=" Dica: Digite o IP e a máscara correspondente ">
								</td>
								<td width="14%"></td>
							</tr>
							<tr>
								<td width="14%"></td>
								<td class="bSearch_cell">
									<input type="submit" value="Buscar" class="bSearch_ip">
								</td>
								<td width="14%"></td>
							</tr>
						</table>
					</fieldset>
				</center>
			</form>
			<%

		PlacaRedeXMaquinas resultIp = null;

		if (request.getParameter("search_ip") != null && !request.getParameter("search_ip").equals("")) {

			String search_ip = request.getParameter("search_ip");
			String rede = "";

			try {

				resultIp = IpBo.getInstance().validateSelectIpDetails(search_ip);

			%>
			<p></p>
				Resultado da busca pelo IP: <span class="key_name" style="font-style:italic;"><%=search_ip%></span>
				<hr class="separate_line"><br/>
			<%
				// verifica se o resultado realmente encontrou o IP.
				if (resultIp == null) {
			%>
			<table width="50%" align="center" border="1" cellpadding="6" cellspacing="0" rules="rows" class="main_table">
				<tr class="alert_line">
					<td align="center">
						<img src="/madmac/icons/file_alert.png" align="middle" width="54px" alt="">
					</td>
					<td align="center">O IP <span style="font-style:italic"><%=search_ip%></span> não referencia nenhuma placa de rede.</td>
				</tr>
			</table>
			<%
				  } else {
			%>
			<table width="60%" align="center" border="0" cellpadding="12" cellspacing="0" rules="all" class="main_table">
				<tr>
					<td width="8%"></td>
					<td class="meta_cell" width="30%">MAC Details</td>
					<td class="data_cell"><%=resultIp.getMac()%></td>
					<td width="8%"></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Setor</td>
					<td class="data_cell_Cap"><%=resultIp.getSetor()%></td>
					<td class="cmd_cell">
						<a href="/madmac/maquina/visualizar_maquinas.jsp?code_setor=<%=resultIp.getCode_setor() %>">
                     <img src="/madmac/icons/computer.png" border="0" title=" Visualizar Máquinas " alt="">
						</a>
					</td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Rede Sem Fio?</td>
					<% if (resultIp.isRede_sem_fio()) {
						  rede = "yes";
					  } else {
						  rede = "no";
					  }
					%>
					<td class="data_cell_Cap">&nbsp;<img src="/madmac/icons/<%=rede%>.gif" alt="<%=rede%>">&nbsp;<%=rede%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Faixa IP</td>
					<td class="data_cell_Cap"><%=resultIp.getFaixa()%></td>
					<td class="cmd_cell">
						<a href="/madmac/ip/visualizar_ips.jsp?faixa_ip=<%=resultIp.getFaixa_ip() %>">
							<img src="/madmac/icons/server_link.png" alt="" border="0"
								  title=" Visualizar IP's da Faixa: <%=resultIp.getFaixa().toUpperCase() %> ">
						</a>
					</td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Tombamento</td>
					<td class="data_cell"><%=resultIp.getTombamento()%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Sistema Operacional</td>
					<td class="data_cell"><%=resultIp.getSistema_op()%></td>
					<td></td>
				</tr>
			</table>

			<%
				}
			} catch (Exception e) {
			%>
			<p><br/></p>
         <table width="45%" align="center" border="1" cellpadding="5" cellspacing="0" rules="rows" class="main_table">
				<tr class="alert_cell">
               <td align="center" width="15%"><img src="/madmac/icons/file_alert.png" align="middle" width="64px" alt=""></td>
					<td><%=e.getMessage()%></td>
				</tr>
			</table>
			<%
			}
		}
			%>
			<br/>
			<hr class="separate_line">

			<p><br/><br/></p>
      </div>
      <div class="footer_madmac">
			<%@include file="/common_pages/footer.jsp" %>
      </div>
   </body>
</html>